﻿using System;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;


namespace FFmpegVideoClip.Lib.Effects
{
    public class BrightnessEffect : ShaderEffect
    {
        private static PixelShader _pixelShader = new PixelShader() { UriSource = MakePackUri("Lib/Effects/Shader/BrightnessEffect.ps") };

        public static Uri MakePackUri(string relativeFile)
        {
            Assembly a = typeof(BrightnessEffect).Assembly;

            // Extract the short name.
            string assemblyShortName = a.ToString().Split(',')[0];

            string uriString = "pack://application:,,,/" +
                assemblyShortName +
                ";component/" +
                relativeFile;

            return new Uri(uriString);
        }
        public BrightnessEffect()
        {
            PixelShader = _pixelShader;

            UpdateShaderValue(InputProperty);
            UpdateShaderValue(BrightnessProperty);
            UpdateShaderValue(AddColorProperty);
        }

        public Brush Input { get => (Brush)GetValue(InputProperty); set => SetValue(InputProperty, value); }
        public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty("Input", typeof(BrightnessEffect), 0);

        public double Brightness { get => (double)GetValue(BrightnessProperty); set => SetValue(BrightnessProperty, value); }
        public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register("Brightness", typeof(double), typeof(BrightnessEffect), new UIPropertyMetadata(1D, PixelShaderConstantCallback(0)));

        public Color AddColor { get => (Color)GetValue(AddColorProperty); set => SetValue(AddColorProperty, value); }
        public static readonly DependencyProperty AddColorProperty = DependencyProperty.Register("AddColor", typeof(Color), typeof(BrightnessEffect),new UIPropertyMetadata(Colors.White, PixelShaderConstantCallback(1)));

        public bool IsMultiply { get => (bool)GetValue(IsMultiplyProperty); set => SetValue(IsMultiplyProperty, value); }
        public static readonly DependencyProperty IsMultiplyProperty = DependencyProperty.Register("IsMultiply", typeof(bool), typeof(BrightnessEffect), new UIPropertyMetadata(((bool)(false)), PixelShaderConstantCallback(2)));
    }
}
